import Vue from 'vue'
import Vuex from 'vuex'
import persistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[]
  },
  getters: {
  },
  mutations: {
    add(state,obj){
      obj.buy=true
      // console.log(obj);
      var index=state.list.findIndex(item=>{
        return  item.id==obj.id
      })
      console.log(index);
      if(index==-1){
        state.list.push(obj)
      }else{
        state.list[index].num+=1
      }
    },
    qx(state,obj){
      console.log(obj);
      // state.list.forEach(item=>{
      //   return item.buy=obj
      // })
    }
  },
  actions: {
  },
  modules: {
  },
  plugins:[persistedState()]
})
